package com.ld.security.cloud.nacos;


import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.java.Log;

import java.util.Arrays;
import java.util.List;


/**
 * Feign请求拦截器
 **/
@Log
public class AuthRequestInterceptor implements RequestInterceptor {

    private static final List<String> loginCookies = Arrays.asList("JSESSIONID","shiroCookie","rememberMe");



    public AuthRequestInterceptor() {

    }

    @Override
    public void apply(RequestTemplate template) {

        log.info("请求预处理");

//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        if (authentication != null) {
//            if (authentication instanceof OAuth2Authentication) {
//                OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
//                String access_token = details.getTokenValue();
//
//                template.header("Authorization", OAuth2AccessToken.BEARER_TYPE + " " + access_token);
//
//                //						template.query(OAuth2AccessToken.ACCESS_TOKEN, access_token);
//
//            }else if(authentication instanceof UsernamePasswordAuthenticationToken){
//                UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = (UsernamePasswordAuthenticationToken)authentication;
//                StringBuffer sb =  new StringBuffer();
//                String authorization = OAuth2AccessToken.BEARER_TYPE + " " + SessionUtil.getCookie(TokenConstants.tokenKey);
//               // String authorization =  SessionUtil.getCookie("Authorization");
//
//              // template.query(OAuth2AccessToken.ACCESS_TOKEN, authorization);
//
//               template.header("Authorization", authorization);
//
//            }
//
//        }
    }
}